package com.centerm.common.view;

import com.centerm.common.constant.ErrorCode;
import com.centerm.common.constant.error.GlobalErrorEnum;

/**
 * JSON返回对象
 * Created by wyp0596 on 21/03/2017.
 */
public class JSONResponse<T> {

    private int code;

    private String msg;

    private T data;

    public JSONResponse() {
    }

    public JSONResponse(ErrorCode response, String msg, T data) {
        this.code = response.getCode();
        this.msg = (msg == null ? response.getMsg() : msg);
        this.data = data;
    }
    
    public JSONResponse(ErrorCode response, String msg) {
        this(response, msg, null);
    }
    
    public JSONResponse(ErrorCode response, T data) {
        this(response, null, data);
    }

    public JSONResponse(T data) {
        this(GlobalErrorEnum.SUCCESS, null, data);
    }

    public JSONResponse(ErrorCode response) {
        this(response, null, null);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    @Override
    public String toString() {
        return "JSONResponse{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
